﻿using System;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YJKArch.NumberRoom
{
	internal class RoomCreater
	{
		public RoomCreater(ExternalCommandData cmdData)
		{
			this.m_Revit = cmdData;
		}

		public Result CreaterRooms(ref string msg)
		{
			this.Search(this.m_Revit.View);
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private void Search(Autodesk.Revit.DB.View view)
		{
			Autodesk.Revit.DB.Document document = this.m_Revit.Application.ActiveUIDocument.Document;
			Level genLevel = this.m_Revit.Application.ActiveUIDocument.ActiveView.GenLevel;
			double num = AssistFunc.mmToFeet(10.0);
			num *= num;
			foreach (object obj in document.get_PlanTopology(genLevel).Circuits)
			{
				PlanCircuit planCircuit = (PlanCircuit)obj;
				if (!planCircuit.IsRoomLocated && !this.LessThan(planCircuit.Area, num))
				{
					document.Create.NewRoom(null, planCircuit);
				}
			}
		}

		private bool LessThan(double val1, double val2)
		{
			return val1 - val2 < -1E-09;
		}

		private ExternalCommandData m_Revit;

		private const double _epsDouble = 1E-09;
	}
}
